home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / 3D_GRAPH / PICTFILE.C < prev    next >
Text File  |  1989-08-26  |  2KB  |  129 lines

  1. /*
  2.     Copyright '89    Christopher Moll
  3.     all etceteras reserved
  4. */
  5.  
  6.  
  7. #include    "graph3D.h"
  8.  
  9. extern    EventRecord        theEvent;
  10. extern    Boolean        grphOnScrn;
  11. extern    WindowPtr        graphWind;
  12.  
  13.  
  14. SavePICT(useObjects)
  15. Boolean    useObjects;
  16. {
  17.     PicHandle    drawPict;
  18.     char    fileName[100];
  19.     int        volRef, fileRef, err;
  20.     long    byteCount;
  21.     Boolean        GetFileID();
  22.     PicHandle    GetGraphPICT();
  23.  
  24.     if (NOT(GetFileID(fileName, "\PSave PICT:", "", &volRef)))
  25.         return;
  26.     drawPict = GetGraphPICT(useObjects);
  27.  
  28.     if (err = Create(fileName, volRef, 'MDPL', 'PICT'))
  29.         goto Fail;
  30.     if (err = FSOpen(fileName, volRef, &fileRef))
  31.         goto Fail;
  32.     if (err = SetEOF(fileRef, 512L))
  33.         goto Fail;
  34.     if (err = SetFPos(fileRef,fsFromStart, 512L))    /* skip header */
  35.         goto Fail;
  36.  
  37.     HLock(drawPict);
  38.     byteCount = GetHandleSize(drawPict);
  39.     if (err = FSWrite(fileRef, &byteCount, *drawPict))
  40.         goto Fail;
  41.     if (err = FSClose(fileRef))
  42.         goto Fail;
  43.     HUnlock(drawPict);
  44.     KillPicture(drawPict);
  45.     return;
  46.  
  47. Fail:
  48.     sprintf(fileName, "Error saving PICT: %d", err);
  49.     GenralAlert(ctop(fileName));
  50. }
  51.  
  52.  
  53.  
  54. /*** act on any update or activate events pending ***/
  55. AllowUpdat()
  56. {
  57.     if (GetNextEvent(updateMask, &theEvent))    /* ROM */
  58.         DoEvent();
  59.     if (GetNextEvent(updateMask, &theEvent))    /* ROM */
  60.         DoEvent();
  61. }
  62.  
  63.  
  64. PicHandle
  65. GetGraphPICT(useObjects)
  66. Boolean    useObjects;
  67. {
  68.     PicHandle    drawPict;
  69.     Boolean        svGraphSt;
  70.  
  71.     if (useObjects)
  72.     {
  73.         svGraphSt = grphOnScrn;
  74.         grphOnScrn = FALSE;
  75.         drawPict = OpenPicture(&graphWind->portRect);
  76.             DrawGraph();
  77.         ClosePicture();
  78.         grphOnScrn = svGraphSt;
  79.     }
  80.     else
  81.     {
  82.         SelectWindow(graphWind);
  83.         AllowUpdat();
  84.  
  85.         RmvGraphGrow();
  86.         DrawRotHndls();
  87.  
  88.         drawPict = OpenPicture(&graphWind->portRect);
  89.             CopyBits(&graphWind->portBits, &graphWind->portBits,
  90.                         &graphWind->portRect, &graphWind->portRect,
  91.                         srcCopy, NIL);
  92.         ClosePicture();
  93.         PutGraphGrow();
  94.         DrawRotHndls();
  95.     }
  96.     return(drawPict);
  97. }
  98.  
  99. static
  100. RmvGraphGrow()
  101. {
  102.     Rect    iconR;
  103.  
  104.     iconR.top = graphWind->portRect.bottom - 16;
  105.     iconR.left = graphWind->portRect.right - 16;
  106.     iconR.bottom = graphWind->portRect.bottom;
  107.     iconR.right = graphWind->portRect.right;
  108.     EraseRect(&iconR);
  109. }
  110.  
  111. Boolean
  112. GetFileID(newfName, prompt, defName, volRefP)
  113. Uchar    *newfName, *prompt, *defName;    /* pascal strings */
  114. int        *volRefP;
  115. {
  116. static    Point    where = {80, 100};
  117.     SFReply     reply;
  118.  
  119.     SFPutFile(where, prompt, defName, NIL, &reply);
  120.  
  121.     if (reply.good)
  122.     {
  123.         *volRefP = reply.vRefNum;
  124.         Pstrcpy(reply.fName, newfName);
  125.         return(TRUE);
  126.     }
  127.     else
  128.         return(FALSE);
  129. }